package com.twu.biblioteca.operation;

import com.twu.biblioteca.exception.InvalidCheckReturnException;
import com.twu.biblioteca.model.Book;
import com.twu.biblioteca.service.BookService;
import com.twu.biblioteca.util.CommonUtils;

import static com.twu.biblioteca.util.Messages.THANK_YOU_FOR_RETURNING_THE_BOOK;
import static java.lang.String.format;

public class ReturnBookOperation extends Operation {
    BookService bookService;

    public void setBookService(BookService bookService) {
        this.bookService = bookService;
    }

    @Override
    public String operate(String[] args) throws InvalidCheckReturnException {
        Book book = bookService.returnBook(CommonUtils.getInputId(args[0]), args[1]);
        return format(THANK_YOU_FOR_RETURNING_THE_BOOK + "|%s|%s|%s",
                book.getBookName(),
                book.getAuthor(),
                book.getYearPublished());
    }

}
